﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.Recycling.Object;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Imaginecup.recycling.Object.Entity;
using Imaginecup.Recycling.GameMan;
using Imaginecup.shareData;
using Microsoft.Xna.Framework.Input;
using System.Diagnostics;
using Imaginecup.util;
using Imaginecup.gameState.recycling.Sprite.Behavior;
using Imaginecup.gameState.recycling.Sprite.Factory;
using Imaginecup.gameState.recycling.Sprite;
using Imaginecup.gameState.recycling;
using Imaginecup.recycling.Object.Menu;

namespace Imaginecup.recycling.Object
{
    public class JumpButton : GameObject
    {
        private IPlayer m_Player;
        private ISprite m_Button;

        public JumpButton(IPlayer obj)
        {
            m_Player = obj;
            Updater.GetInstance().AddUpdate(this);
        }
        protected override void Initialize()
        {
            base.Initialize();
            m_TextureName = "JumpButton";
            Texture2D m_Texture = ResourceManager.GetInstance().GetContent(m_TextureName);
            m_Info = new ObjectInfo
            (
                new Vector2(0 , 379),
                new Rectangle(0, 379, m_Texture.Width/2, m_Texture.Height)
            );
            m_Info.FrameWidth = m_Texture.Width/2;
            m_Info.FrameHeight = m_Texture.Height;
            m_Button = SpriteFactory.GetInstance().GetObject(SpriteID.TOGGLE_SPRITE, m_Info, "JumpButton") as ISprite;
            RenderDrawer.GetInstance().AddSprite(m_Button);
        }

//         public override void Draw(SpriteBatch spriteBatch, GameTime gametime)
//         {
//             m_Button.Draw(spriteBatch, gametime);
//         }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            MouseState mouse = MouseInputHandler.GetInputHandler().MouseState;

            if (mouse.LeftButton == ButtonState.Pressed)
            {
                if (SourceCollision.Contains(mouse.X, mouse.Y))
                {
                    // 스프라이트의 상태를 변경
                    (m_Button as IButton).SetButtonState(Button_State.PRESSED);

                    if (m_Player.IsAnimationPlay() && m_Player.IsOnGround())
                    {
                        m_Player.AnimationChange(CharacterState.Jump);
                        m_Player.JumpCharacter();
                    }
                }
            }
            else if (mouse.LeftButton == ButtonState.Released)
            {
                // 스프라이트의 상태를 변경
                if (SourceCollision.Contains(mouse.X, mouse.Y))
                    (m_Button as IButton).SetButtonState(Button_State.NONE);
            }
        }
    }
}
